<?php 

function check_url($url)
{
	$url_arr=parse_url($url);//将url分解成关联数组
	$path=(isset($url_arr['path']))?$url_arr['path']:'/';//验证‘path’路径值是否为真，如果有值将值赋给变量$path;
	$port=(isset($urk_arr['port']))?$url_arr['port']:'80';//同上，验证端口号，并把值赋给$port;
	if($fp=fsockopen($url_arr['host'],$port,$errno,$errstr,30))
	{
		$send="HEAD $path HTTP/1.1\r\n";
		$send.="HOST:{$url_arr['host']}\r\n";
		$send.="CONNECTION:close\r\n\r\n";
		fwrite($fp, $send);//向服务器中写入数据
		$data=fgets($fp,128);//读取获取到的HTTP头文件中的128字符；
		fclose($fp);//关闭文件读取
		list($re,$code)=@explode(' ', $data);//将数组$data中的值赋给变量$re,$code;
		if($code==200)
		{
			return array($code,'good');
		}
		else
		{
			return array($code,'bad');
		}
		
	}
	else
		{
			return array($errstr,'bad');
		}

}//check_url()结束
$urls=array(
'http://weibo.com/u/2943395937/home?end_id=3988412824193037&pre_page=1&page=2',
'https://www.baidu.com/index.php?tn=56060048_4_pg',
'http://www.ecjtuit.com.cn',
'http://findphone.vivo.com.cn/login/start'

	);
echo "<h1>validate URLS:</h1>";
set_time_limit(0);//取消PHP请求的时间限制
foreach($urls as $url)
{
	list($code,$class)=check_url($url);
	echo "<p><a href=\"$url\" target=\"new\">$url($code)</a></p>";
}
 ?>